//
//  ViewController.m
//  UI03_UIViewController_CustomView
//
//  Created by Scott on 16/3/11.
//  Copyright © 2016年 Scott. All rights reserved.
//

#import "ViewController.h"
#import "LTView.h"
#import "MyButton.h"
#import "VCOfSecond.h"

// 延展
@interface ViewController () <UITextFieldDelegate>

@end

@implementation ViewController

/** 初始化 */
- (instancetype)init {
    
    self = [super init];
    if (self) {

        NSLog(@"%s, %d", __FUNCTION__, __LINE__);
    }
    return self;
}

/** 首先从图像化(nib)进行初始化, 如果没有nib文件, 尝试从代码初始化. 所以无论是图形化进入还是代码进入, 都会调用这个初始化方法. 所以,通常重写controller的初始化都是重写这个方法. */
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
        NSLog(@"%s, %d", __FUNCTION__, __LINE__);

    }
    return self;
    
    
}

/** 加载视图. */
- (void)loadView {
    [super loadView];
    
    NSLog(@"%s, %d", __FUNCTION__, __LINE__);
    
}

/** 
 * 视图加载完毕.
 * 通常, 代码是在此方法编写.
 */
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    NSLog(@"%s, %d", __FUNCTION__, __LINE__);

    [self createSubviews];
    
}


- (void)createSubviews {
    
    // 用户名
    LTView *viewOfUser = [[LTView alloc] initWithFrame:CGRectMake(40, 50, self.view.frame.size.width - 80, 40) withText:@"用户名:" placeHolder:@"请输入用户名"];
    [self.view addSubview:viewOfUser];
    [viewOfUser release];
    
    viewOfUser.textFieldOfRight.delegate = self;
    
    
    // 密码
    LTView *viewOfPasswd = [[LTView alloc] initWithFrame:CGRectMake(40, 110, self.view.frame.size.width - 80, 40) withText:@"密码:" placeHolder:@"请输入密码"];
    [self.view addSubview:viewOfPasswd];
    [viewOfPasswd release];
    
    viewOfPasswd.textFieldOfRight.delegate = self;
 
    // 确定button
    MyButton *buttonOfConfirm = [MyButton buttonWithType:UIButtonTypeSystem];
    buttonOfConfirm.frame = CGRectMake(40, 180, 100, 40);
    
    [self.view addSubview:buttonOfConfirm];
    
    [buttonOfConfirm setTitle:@"确定" forState:UIControlStateNormal];
    
    // 注册button
    MyButton *buttonOfReg = [MyButton buttonWithType:UIButtonTypeSystem];
    buttonOfReg.frame = CGRectMake(200, 180, 100, 40);
    
    [self.view addSubview:buttonOfReg];
    
    [buttonOfReg setTitle:@"注册" forState:UIControlStateNormal];
    
    
    [buttonOfReg addTarget:self action:@selector(handleReg:) forControlEvents:UIControlEventTouchUpInside];
    
}

#pragma mark - 跳转下一页面.
- (void)handleReg:(UIButton *)button {
    
    // 创建第二页面对象.
    VCOfSecond *second = [[VCOfSecond alloc] init];
    
    // 模态推出第二界面.(controller方法)
    [self presentViewController:second animated:YES completion:^{
        
    }];
    
    [second release];
    
}


#pragma mark - UITextField Delegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    
    [textField resignFirstResponder];
    
    return YES;
}


#pragma mark - other
/** 视图将要显示. */
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    NSLog(@"%s, %d", __FUNCTION__, __LINE__);
    
}

/** 视图已经显示. */
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    
    NSLog(@"%s, %d", __FUNCTION__, __LINE__);
    
}

/** 内存不足时, 调用此方法. */
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    NSLog(@"%s, %d", __FUNCTION__, __LINE__);
    
    
    
}


@end




